﻿using DevExpress.Data.Filtering;
using DevExpress.Mvvm.Gantt;
using DevWpfApp.ResourceManage;
using log4net;
using Microsoft.Win32;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Threading;

namespace DevWpfApp
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        string version = "2021.4.22";
        public MainWindow()
        {
            log.Debug("====== 软件启动，版本："+version);
            Application.Current.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            
            InitializeComponent();
        }

        #region logger

        public static ILog log = LogManager.GetLogger("DevWpfApp");
        private void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            var comException = e.Exception as System.Runtime.InteropServices.COMException;

            if (comException != null && comException.ErrorCode == -2147221040)
            {
                e.Handled = true;
            }
            else
            {

                log.Error(e.Exception.StackTrace);
                log.Error(e.Exception.Message);
            }
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            log.Error((e.ExceptionObject as Exception).StackTrace);
            log.Error((e.ExceptionObject as Exception).Message);
        }

        #endregion

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.Title = " YYApp epicblue@qq.com ver: " + version;
        }


    }
}
